package cn.itcast.flink.transformation;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author itcast
 * Date 2022/1/11 17:09
 * Desc TODO
 */
public class Filter2Demo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<String> source = env.fromElements("abc123", "bcd", "192.168.0.1", "hello flink");
        SingleOutputStreamOperator<String> result = source.filter(
                new FilterFunction<String>() {
                    @Override
                    public boolean filter(String value) throws Exception {
                        return value.contains("flink");
                    }
                }
        );
        result.printToErr();
        source.filter(t->t.contains("flink")).printToErr();
        env.execute();
    }
}
